package com.guaju.yueshangLife.activity.setting;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.view.View;

import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.base.BaseActivity;
import com.guaju.yueshangLife.databinding.ActivityConfirmPayPassBinding;
import com.guaju.yueshangLife.textwatcher.SimpleTextWatcher;
import com.guaju.yueshangLife.utils.ToastUtil;

public class ConfirmPayPassActivity extends BaseActivity {


    private ActivityConfirmPayPassBinding binding;
    private String pay_pass;

    private StringBuilder sb;

    @Override
    protected void loadViewLayout() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_confirm_pay_pass);

    }

    @Override
    protected void bindViews() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        Intent intent = getIntent();
        pay_pass = intent.getStringExtra("pay_pass");

    }

    @Override
    protected void setListener() {
        binding.et1.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            protected void afterTxtChanged(Editable s) {
                if (!TextUtils.isEmpty(s)) {
                    sb.append(s);
                    binding.et2.requestFocus();
                }
            }
        });
        binding.et2.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            protected void afterTxtChanged(Editable s) {
                if (!TextUtils.isEmpty(s)) {
                    sb.append(s);
                    binding.et3.requestFocus();
                } else {
                    binding.et1.requestFocus();
                }
            }

        });
        binding.et3.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            protected void afterTxtChanged(Editable s) {
                if (!TextUtils.isEmpty(s)) {
                    sb.append(s);
                    binding.et4.requestFocus();
                } else {
                    binding.et2.requestFocus();
                }
            }
        });
        binding.et4.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            protected void afterTxtChanged(Editable s) {
                if (!TextUtils.isEmpty(s)) {
                    sb.append(s);
                    binding.et5.requestFocus();
                } else {
                    binding.et3.requestFocus();
                }
            }
        });
        binding.et5.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            protected void afterTxtChanged(Editable s) {
                if (!TextUtils.isEmpty(s)) {
                    sb.append(s);
                    binding.et6.requestFocus();
                } else {
                    binding.et4.requestFocus();
                }
            }
        });
        binding.et6.addTextChangedListener(new SimpleTextWatcher() {
            @Override
            protected void afterTxtChanged(Editable s) {
                if (!TextUtils.isEmpty(s)) {
                    sb.append(s);
                    binding.btSubmit.setBackgroundResource(R.drawable.shape_login_enable_bg);
//                    自动跳转到确认
                    if (TextUtils.equals(s, sb.toString())) {
                        //TODO


                    } else {
                        ToastUtil.show("密码不一致，请您重新输入");
                    }

                } else {
                    binding.et5.requestFocus();
                }
            }
        });
        binding.btSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                设置完密码
            }
        });


    }
}
